package com.imooc.order;

import com.imooc.order.fallback.addressservice.AddressServiceFeignClient;
import com.imooc.order.fallback.itemservice.ItemCommentsFeignClient;
import com.imooc.order.fallback.itemservice.ItemServiceFeignClient;
import com.imooc.user.service.UserService;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.spring.annotation.MapperScan;

/**
 * MapperScan 扫描 mybatis 通用 mapper 所在的包
 * ComponentScan 扫描所有包以及组件包
 *
 * @author: 顾志杰
 */
@SpringBootApplication
@MapperScan(basePackages = "com.imooc.order.mapper")
@ComponentScan(basePackages = {"com.imooc", "org.n3r.idworker"})
@EnableFeignClients(
        clients = {
                ItemCommentsFeignClient.class,
                ItemServiceFeignClient.class,
                UserService.class,
                AddressServiceFeignClient.class
        }
//        basePackages = {
//                "com.imooc.user.service",
//                "com.imooc.item.service",
//                "com.imooc.order.fallback.itemservice"
//        }
)
@EnableEurekaClient
@EnableCircuitBreaker
public class OrderApplication {

    @Bean
    public RestTemplate register() {
        return new RestTemplate();
    }

    public static void main(String[] args) {
        new SpringApplicationBuilder(OrderApplication.class)
                .web(WebApplicationType.SERVLET)
                .run(args);
    }
}
